﻿package com.tudou.v2
{
    import com.tudou.consts.*;
    import com.tudou.fast.*;
    import com.tudou.track.*;

    public class VideoInfoCompatV2 extends VideoInfo
    {
        private var original:Boolean = false;
        private var errorType:int = 0;
        private var maxRateType:int;

        public function VideoInfoCompatV2(param1:Object, param2:String, param3:int, param4:int, param5:Boolean, param6:String)
        {
            super(param1, param2, param3, param6);
            this.maxRateType = param4;
            this.original = param5;
            compatV2();
            return;
        }// end function

        protected function processError() : void
        {
            var _loc_1:Array = null;
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            _loc_2 = maxRateType;
            while (_loc_2 >= 0)
            {
                
                _loc_1 = rateURLSet[_loc_2];
                _loc_3 = _loc_2 - 1;
                while ((_loc_1 == null || _loc_1.length == 0) && _loc_3 >= 0)
                {
                    
                    _loc_1 = rateURLSet[_loc_3];
                    _loc_3 = _loc_3 - 1;
                }
                rateURLSet[_loc_2] = _loc_1;
                _loc_2 = _loc_2 - 1;
            }
            _loc_2 = 0;
            while (_loc_2 <= maxRateType)
            {
                
                _loc_1 = rateURLSet[_loc_2];
                _loc_3 = _loc_2 + 1;
                while ((_loc_1 == null || _loc_1.length == 0) && _loc_3 <= maxRateType)
                {
                    
                    _loc_1 = rateURLSet[_loc_3];
                    _loc_3++;
                }
                rateURLSet[_loc_2] = _loc_1;
                _loc_2++;
            }
            if (maxRateType == RateType.P720)
            {
                rateURLSet[RateType.P480] = null;
            }
            var _loc_4:* = rateURLSet[RateType.ORIGINAL];
            if (original && (_loc_4 == null || _loc_4.length == 0))
            {
                rateURLSet[RateType.ORIGINAL] = rateURLSet[maxRateType];
            }
            return;
        }// end function

        private function compatV2() : void
        {
            var _loc_1:Array = null;
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            if (_v2ErrorNo != 0)
            {
                return;
            }
            var _loc_4:int = 1;
            errorType = 0;
            _loc_2 = 0;
            while (_loc_2 <= maxRateType)
            {
                
                _loc_1 = rateURLSet[_loc_2];
                if (_loc_1 == null || _loc_1.length == 0)
                {
                    errorType = errorType + _loc_4;
                }
                _loc_4 = _loc_4 * 2;
                _loc_2++;
            }
            if (maxRateType == RateType.P720)
            {
                errorType = errorType & (256 - 1) - 4;
            }
            _loc_1 = rateURLSet[RateType.ORIGINAL];
            if (original && (_loc_1 == null || _loc_1.length == 0))
            {
                errorType = errorType + 128;
            }
            if (errorType > 0)
            {
                ErrorReportTracker.send(_iid, ErrorReportTracker.V2_CACHE_ERROR, "v2CacheErr", errorType);
                ErrorTracker.send(sourceId, ErrorTracker.V2_CACHE_ERROR, 0, v2URL, v2StrXML);
            }
            processError();
            return;
        }// end function

        override public function getCurrVideoNodeInfo(param1:int) : VideoNodeInfo
        {
            var _loc_2:* = rateURLSet[param1];
            if (_loc_2 && _loc_2.length > 0)
            {
                return _loc_2[0];
            }
            processError();
            _loc_2 = rateURLSet[param1];
            if (_loc_2 && _loc_2.length > 0)
            {
                return _loc_2[0];
            }
            if (urlLength > 0)
            {
                ErrorReportTracker.send(_iid, ErrorReportTracker.CAN_NOT_PLAY, FastTudouNew.inst.version, ErrorReportTracker.CAN_NOT_PLAY_USE_UP_ALL_URLS);
                ErrorTracker.send(sourceId, ErrorTracker.CAN_NOT_PLAY, ErrorTracker.CAN_NOT_PLAY_USE_UP_ALL_URLS, v2URL, v2StrXML);
            }
            else
            {
                ErrorReportTracker.send(_iid, ErrorReportTracker.CAN_NOT_PLAY, "noURLs", ErrorReportTracker.CAN_NOT_PLAY_NO_URL);
                ErrorTracker.send(sourceId, ErrorTracker.CAN_NOT_PLAY, ErrorTracker.CAN_NOT_PLAY_NO_URL, v2URL, v2StrXML);
            }
            return new VideoNodeInfo();
        }// end function

    }
}
